package net.dntuan.jaxbdemo.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public abstract class AbstractDateAdapter extends XmlAdapter<String, Date> {
	protected SimpleDateFormat dateFormat;

	public AbstractDateAdapter() {
		dateFormat = new SimpleDateFormat();
		applyPattern();
	}

	protected abstract void applyPattern();

	protected DateFormat getDateFormat() {
		return this.dateFormat;
	}

	@Override
	public String marshal(Date date) throws Exception {
		return dateFormat.format(date);
	}

	@Override
	public Date unmarshal(String string) throws Exception {
		return dateFormat.parse(string);
	}
}
